package com.example.demo.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Create with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-08-27
 * Time:10:13
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public boolean login(HttpServletRequest request, String username, String password) {
        boolean result = false;
        if (StringUtils.hasLength(username) && StringUtils.hasLength(password)) {
            if (username.equals("admin") && password.equals("admin")) {
                HttpSession session = request.getSession();
                session.setAttribute("userinfo", "userinfo");
                return true;
            }
        }
        return result;
    }

    @RequestMapping("/index1")
    public String index1() {
        String result = "Hello index";
        return result;
    }

    @RequestMapping("/index2")
    public String index2() {
        int num = 10 / 0;
        return "hello,index2.";
    }
}
